package com.company.project.web;
import com.company.project.core.Result;
import com.company.project.core.ResultGenerator;
import com.company.project.model.CarPool;
import com.company.project.model.CarPoolVo;
import com.company.project.service.CarPoolService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
* Created by CodeGenerator on 2023/11/21.
*/
@RestController
@RequestMapping("/car/pool")
public class CarPoolController {
    @Resource
    private CarPoolService carPoolService;

    @PostMapping("/add")
    public Result add(CarPool carPool) {
        carPoolService.save(carPool);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/delete")
    public Result delete(@RequestParam Integer id) {
        carPoolService.deleteById(id);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/update")
    public Result update(CarPool carPool) {
        carPoolService.update(carPool);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/detail")
    public Result detail(@RequestParam Integer id) {
        CarPool carPool = carPoolService.findById(id);
        return ResultGenerator.genSuccessResult(carPool);
    }

    @PostMapping("/list")
    public Result list(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer size) {
        PageHelper.startPage(page, size);
        List<CarPool> list = carPoolService.findAll();
        PageInfo pageInfo = new PageInfo(list);
        return ResultGenerator.genSuccessResult(pageInfo);
    }

    @GetMapping("/mobile/list")
    public Result mobileList(CarPool carPool) {
        List<CarPoolVo> carPoolList = carPoolService.findMobileList(carPool);
        return ResultGenerator.genSuccessResult(carPoolList);
    }


}
